package com.example.devtool.core.common;

import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

/**
 * @author zhuliangxuan
 * @date 2022/5/22 22:02
 */
@Data
public class BaseResponse<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = -711215870225967210L;

    private Integer code;
    private String message;
    private T data;

    public static <T> BaseResponse<T> success() {
        BaseResponse<T> baseResponse = new BaseResponse<>();
        baseResponse.setCode(0);
        baseResponse.setMessage("success");
        return baseResponse;
    }

    public static <T> BaseResponse<T> success(T t) {
        BaseResponse<T> baseResponse = new BaseResponse<>();
        baseResponse.setCode(0);
        baseResponse.setMessage("success");
        baseResponse.setData(t);
        return baseResponse;
    }

    public static <T> BaseResponse<T> error(String message) {
        BaseResponse<T> baseResponse = new BaseResponse<>();
        baseResponse.setCode(500);
        baseResponse.setMessage(message);
        return baseResponse;
    }
}
